﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EcomProduct.Web.UI;
using EcomProduct.Data;
using EcomProduct.Entities;

public partial class Admin_Article : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        FormUtil.RedirectAfterUpdate(GridView1, "Article.aspx?page={0}");
        FormUtil.SetPageIndex(GridView1, "page");
        FormUtil.SetDefaultButton((Button)GridViewSearchPanel1.FindControl("cmdSearch"));

        DropDownList cboFieldName = (DropDownList)GridViewSearchPanel1.FindControl("cboFieldName");
        cboFieldName.Items.Clear();
        cboFieldName.Items.Add(new ListItem("Tiêu đề", "Title"));
        cboFieldName.Items.Add(new ListItem("Tiêu đề chuyên mục", "MenuTitle"));
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string urlParams = string.Format("Id={0}", GridView1.SelectedDataKey.Values[0]);
        Response.Redirect("ArticleEdit.aspx?" + urlParams, true);
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string ID = e.CommandArgument.ToString().Trim();
        if (e.CommandName == "CustomDelete")
        {
            Article obj = new Article();
            obj.Id = Convert.ToInt64(ID);
            DataRepository.ArticleProvider.Delete(obj);

            //TList<Article> objPodetail = DataRepository.PoDetailsProvider.GetByPoId(poID);
            //if (objPodetail.Count > 0)
            //{
            //    Response.Write(@"<script language='javascript'>alert('Vui lòng xóa tất cả chi tiết.')</script>");

            //}
            //else
            //{
            //    Pharmacy.Entities.Po objPo = new Pharmacy.Entities.Po();
            //    objPo.PoId = poID;
            //    DataRepository.PoProvider.Delete(objPo);
            //}
            // Thuc hien xoa
            // Lam sau
            GridView1.DataBind();
        }
        else if (e.CommandName == "CustomDisable")
        {
            Article obj = DataRepository.ArticleProvider.GetById(Convert.ToInt64(ID));
            obj.IsDisabled = !obj.IsDisabled;
            DataRepository.ArticleProvider.Update(obj);

            GridView1.DataBind();
        }
        else if (e.CommandName == "CustomEdit")
        {
            Response.Redirect("~/Admin/ArticleEdit.aspx?Id=" + ID);
        }
    }
}
